/**  
 * Copyrights@2006, Tianyuan DIC Information Co.,Ltd.
 * 文件名:    TMallResponseService.java  
 * 描述:   
 * 作者:     kaiyang
 * 版本:    1.0  
 * 创建时间:   2015年5月4日 上午10:01:35  
 *  
 * 修改历史:  
 * 日期                          作者           版本         描述  
 * ------------------------------------------------------------------  
 * 2015年5月4日      kaiyang      1.0        1.0 Version  
 */ 
package com.hp.bon.sgw.wh.service;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;

/**  
 * @ClassName: TMallResponseService   
 * @Description: TODO  
 * @author: kaiyang  
 * @date:2015年5月4日 上午10:01:35     
 */
public class TMallResponseService {
	private Configuration cfg = null;
    private Template template = null;
    private Template template1 = null;
    private Template template2 = null;
	private static final Logger _log = LoggerFactory.getLogger(TMallResponseService.class);
	
    public void init() throws IOException
    {
	    this.cfg = new Configuration();
	    this.cfg.setClassForTemplateLoading(getClass(), "/");
	    this.cfg.setDefaultEncoding("UTF-8");
	    
	    template = this.cfg.getTemplate("tmall.ftl");
	    template.setEncoding("UTF-8");
	    
	    template1 = this.cfg.getTemplate("taobao.ftl");
	    template1.setEncoding("UTF-8");
	    
	    template2 = this.cfg.getTemplate("pointExchange.ftl");
	    template2.setEncoding("UTF-8");
	}

	public String getResponse(Map<String, String> data)
	{
	    String context = "";
	    if (template != null)
	    {
	      StringWriter writer = new StringWriter();
	      try {
	        template.process(data, writer);
	      } catch (Exception e) {
	        _log.error("TMallResponseService getResponse error, msg = {}", e.getMessage());
	        e.printStackTrace();
	      }
	      context = writer.toString();
	    }
	    _log.info("response = {}",context);
	    return context;
	   
	}
	
	
	public String getResponse1(Map<String, String> data)
	{
	    String context = "";
	    if (template1 != null)
	    {
	      StringWriter writer = new StringWriter();
	      try {
	        template1.process(data, writer);
	      } catch (Exception e) {
	        _log.error("TMallResponseService getResponse error, msg = {}", e.getMessage());
              _log.error("",e);
	      }
	      context = writer.toString();
	    }
	    _log.info("response = {}",context);
	    return context;
	   
	}
	
	public String getResponse2(Map<String, String> data)
	{
	    String context = "";
	    if (template2 != null)
	    {
	      StringWriter writer = new StringWriter();
	      try {
	        template2.process(data, writer);
	      } catch (Exception e) {
	        _log.error("TMallResponseService getResponse error, msg = {}", e.getMessage());
	        e.printStackTrace();
	      }
	      context = writer.toString();
	    }
	    _log.info("response = {}",context);
	    return context;
	   
	}
}
